package reflect;

import java.lang.reflect.Constructor;

/*
* 操作特定构造器进行对象实例化
* */
public class ReflectDemo3 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        //无参构造器
        //Constructor constructor = cls.getConstructor();
        //constructor.newInstance();
        //一个参数的
        Constructor constructor = cls.getConstructor(String.class);
        Object obj = constructor.newInstance("李四");
        System.out.println(obj);
        //两个参数
        Constructor constructor2 = cls.getConstructor(String.class,int.class);
        Object obj2 = constructor2.newInstance("王五",23);
        System.out.println(obj2);
    }
}
